package com.erp.module.ProductionExecute

import android.content.Context
import android.util.Log
import com.erp.Interface.OnUserDataInterface
import com.erp.contacts.Contacts
import com.erp.mclass.QuanXian
import com.erp.module.ProductionExecuter.FragmengtProductionExecute
import com.erp.util.Httputil
import org.xutils.http.RequestParams
import org.xutils.x

class ProductionExecuteM {
    fun getProductionList(context: Context, page: Int, pagesize: Int,sousuobean:FragmengtProductionExecute.SousuoBean, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.PRODUCTION_MATERIAL)
        Log.d("onSuccess","ssss"+page.toString())
        Httputil.getparams(context, params)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize", pagesize.toString())

        params.addBodyParameter("searchParams[expect_accomplish_time_sort]", "asc")
        if(sousuobean.workshop != ""){
            params.addBodyParameter("searchParams[workshop]", sousuobean.workshop.trim())
        }
        if(sousuobean.category != ""){
            params.addBodyParameter("searchParams[category]", sousuobean.category.trim())
        }
        if(sousuobean.id != ""){
            params.addBodyParameter("searchParams[id]", sousuobean.id.trim())
        }
        when(sousuobean.stock){
            "已备料" -> {
                params.addBodyParameter("searchParams[stock]", "1")
                params.addBodyParameter("searchParams[status][0]", "2")
            }
            "未备料" -> {
                params.addBodyParameter("searchParams[stock]", "0")
                params.addBodyParameter("searchParams[status][0]", "2")
            }
            "请求送料" -> {
                params.addBodyParameter("searchParams[status][0]", "3")
            }
            "送料中" -> {
                params.addBodyParameter("searchParams[status][0]", "4")
            }
            else ->{
                params.addBodyParameter("searchParams[status][0]", "2")
                params.addBodyParameter("searchParams[status][1]", "3")
                params.addBodyParameter("searchParams[status][2]", "4")
            }
        }
        if(sousuobean.start_time != "" && sousuobean.end_time != ""){
            params.addBodyParameter("searchParams[time_filter][time_category]", "batch.productive_time")
            params.addBodyParameter("searchParams[time_filter][start_time]", sousuobean.start_time)
            params.addBodyParameter("searchParams[time_filter][end_time]", sousuobean.end_time)
        }
        Log.d("TAAG",sousuobean.toString())
        x.http().get<String>(params, Httputil.Call(context, onUserDataInterface))
    }

    fun ProductionSongliao(context: Context,plmd_id :String , status : String ,onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.PRODUCTION_MATERIAL+"/production_load_material_execute_accomplish")
        Httputil.getparams(context, params)
        Httputil.addtoken(params)
        params.addBodyParameter("plmd_ids[0]",plmd_id, Contacts.BOUNDARY)
        params.addBodyParameter("status",status, Contacts.BOUNDARY)
        params.addHeader("ACCEPT", "application/json")
        x.http().post<String>(params, Httputil.Call(context, onUserDataInterface))
    }
    fun ProductionShouLiao(context: Context,plmd_id :String , status : String ,onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.PRODUCTION_MATERIAL+"/production_load_material_execute_on")
        Httputil.getparams(context, params)
        Httputil.addtoken(params)
        params.addBodyParameter("plmd_ids[0]",plmd_id, Contacts.BOUNDARY)
        params.addBodyParameter("status",status, Contacts.BOUNDARY)
        params.addHeader("ACCEPT", "application/json")
        x.http().post<String>(params, Httputil.Call(context, onUserDataInterface))
    }
    fun ProductionWancheng(context: Context,plmd_id :String ,onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.PRODUCTION_MATERIAL+"/production_load_material_affirm_accomplish")
        Httputil.getparams(context, params)
        Httputil.addtoken(params)
        params.addBodyParameter("plmd_ids[0]",plmd_id, Contacts.BOUNDARY)
        params.addBodyParameter("","", Contacts.BOUNDARY)
        params.addHeader("ACCEPT", "application/json")
        x.http().post<String>(params, Httputil.Call(context, onUserDataInterface))
    }
    //获取物料类别列表
    fun getcategorys(context: Context,onUserDataInterface: OnUserDataInterface){
        val params = RequestParams(Contacts.PRODUCTION_MATERIAL+"/configuration/material_category")
        Httputil.getparams(context, params)
        params.addHeader("ACCEPT", "application/json")
        x.http().get<String>(params, Httputil.Call(context, onUserDataInterface))
    }

    //获取供应商列表
    fun getGongyingshangLieBiao(context: Context, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.PRODUCTION_MATERIAL+"/configuration/inventory_supplier")
        Httputil.getparams(context, params)
        x.http().get(params, Httputil.Call(context, onUserDataInterface))
    }
    //修改供应商
    fun  setGongyingshang(context: Context,plmdyhh_id:String,iu_id:String, onUserDataInterface: OnUserDataInterface){
        val params = RequestParams(Contacts.PRODUCTION_MATERIAL+"/production_inventory_supplier")
        Httputil.getparams(context, params)
        Httputil.addtoken(params)
        params.addBodyParameter("plmdyhh_id",plmdyhh_id, Contacts.BOUNDARY)
        params.addBodyParameter("iu_id",iu_id, Contacts.BOUNDARY)
        params.addHeader("ACCEPT", "application/json")
        x.http().post<String>(params, Httputil.Call(context, onUserDataInterface))
    }
}